package com.zby.utils;

import lombok.Data;

@Data
public class Result<T> {
    /**
     * 响应码
     */
    private int code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;
    // 构造方法
    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(int code, T data) {
        this.code = code;
        this.data = data;
    }

    // 成功时的返回
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data);
    }
    public static <T> Result<T> success() {
        return new Result<>(200, "成功",null);
    }
    public static <T> Result<T> success(int code,T  data) {
        return new Result<>(code, data);
    }
    // 失败时的返回
    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message, null);
    }
}
